home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $PROJECT: HyperText-DataType-System
- **
- ** $VER: AddTOCEntry.rexx 40.5 (30.12.96)
- **
- ** by
- **
- ** Stefan Ruppert , Windthorststrasse 5 , 65439 Floersheim , GERMANY
- **
- ** (C) Copyright 1996
- ** All Rights Reserved !
- **
- ** $HISTORY:
- **
- ** 30.12.96 : 040.005 : added FLUSH command and UniView support
- ** 27.10.96 : 040.004 : use rexxdossupport.library
- ** 16.09.96 : 040.003 : added some comments
- ** 31.08.96 : 040.002 : added NODENAME field
- ** 29.08.96 : 040.001 : initial
- **
- */
-
- Options Results
-
- Parse Arg args
-
- /* --------------------------- needed libraries --------------------------- */
-
- Call AddLib('rexxsupport.library',0,-30,0)
- Call AddLib('rexxdossupport.library',0,-30,0)
-
- Parse Arg args
-
- rxport = ''
- stem.title = ''
- stem.path = ''
- stem.nodename = ''
- stem.verbose = 0
- stem.debug = 0
-
- If ReadArgs(args,'TITLE,PATH,NODENAME,VERBOSE/S,DEBUG/S','STEM.') Then Do
-
- /* if no arguments are given from command line, try to get information
- * from MultiView. This uses the hypertext.datatype ARexx port.
- */
- If stem.title = '' | stem.path = '' Then Do
- rxport = ADDRESS()
- if Right(rxport,4) ~= '.1.1' Then
- rxport = rxport || '.1'
-
- If ~Show(Ports,rxport) Then
- Do
- rxport = 'UNIVIEW.1.1'
-
- If ~Show(Ports,rxport) Then
- Do
- rxport = 'MULTIVIEW.1.1'
- If ~Show(Ports,rxport) Then
- Do
- rxport = 'HYPERTEXTDT.1'
- If ~Show(Ports,rxport) Then
- Do
- Say 'Multiview not started or displays a none HyperText object'
- Exit 10
- End
- End
- End
- End
-
- If (stem.verbose) Then
- Say rxport
-
- ADDRESS VALUE rxport
-
- /* Obtain current object information */
- 'GETATTR OBJECT=OBJECT FIELD=TITLE VAR="STEM.TITLE"'
- 'GETATTR OBJECT=OBJECT FIELD=PATH VAR="STEM.PATH"'
- 'GETATTR OBJECT=OBJECT FIELD=NODENAME VAR="STEM.NODENAME"'
- End
-
- If (stem.verbose) Then
- Do
- Say stem.path
- Say stem.title
- Say stem.nodename
- End
-
- /* Get Global TOC file name */
- tocfile = 'Help:' || GetVar('Language') || '/HTDS_TOC.hguide'
- tmpfile = 'T:ate' || Time(s)
-
- file = Strip(Trim(stem.path))
- title = Strip(Trim(stem.title))
-
- filename = FilePart(file)
- letter = Upper(Left(Strip(filename),1))
-
- if Length(stem.nodename) > 0 Then Do
- If Right(file,1) ~= ':' & Right(file,1) ~= '/' Then
- file = file || '/'
- file = file || stem.nodename
- End
-
- /* try to flush the TOC file from the hypertext object */
- If (rxname ~= '') Then
- Do
- If stem.verbose Then
- Say 'Flush ' || tocfile
- 'FLUSH DOCUMENT="' || tocfile || '"'
- End
-
- /* add a entry in the global table of contents file, sorted by the initial
- * letter.
- *
- * Implemented as a state machine.
- */
-
- state = ''
- If Open('tmp',tmpfile,'w') Then Do
- If Open('toc',tocfile,'r') Then Do
- state = 'begin'
- Do While ~Eof('toc')
- line = ReadLn('toc')
-
- If (stem.debug) Then Do
- Say 'State : ' || state
- Say Line
- End
-
- Select
- When state = 'begin' Then Do
- /* search for the beginning of the link section */
- If line = '@remark HTDS_TOC BEGIN' Then
- state = 'table'
- Call WriteLn('tmp',line)
- End
- When state = 'table' Then Do
- /* now search for the appropriate initial letter */
- If Left(line,11) = '@{m_letter ' Then Do
- If SubStr(line,12,1) = letter Then
- state = 'insert'
- Else if SubStr(line,12,1) > letter Then Do
- Call WriteLn('tmp','@{m_letter ' || letter || '}')
- Call WriteLn('tmp','@{" ' || filename || ' " link "' || file || '"}@{tab}' || title)
- Call WriteLn('tmp','')
- state = 'end'
- End
-
- Call WriteLn('tmp',line)
- End
- Else If line = '@remark HTDS_TOC END' then Do
- /* now entry found with the same letter, just append the current one */
- Call WriteLn('tmp','@{m_letter ' || letter || '}')
- Call WriteLn('tmp','@{" ' || filename || ' " link "' || file || '"}@{tab}' || title)
- Call WriteLn('tmp','')
- state = 'end'
-
- Call WriteLn('tmp',line)
- End
- Else
- Call WriteLn('tmp',line)
- End
- When state = 'insert' Then Do
- /* there exist some entries with the same initial letter, now sort
- * it within these entries
- */
-
- Parse Var line '@{" ' linefilename ' " link "' linkname '"}@{tab}' rest
- rest = Strip(Trim(rest))
- linefilename = Strip(Trim(linefilename))
- If line = '' | Upper(filename) <= Upper(linefilename) Then Do
- If (linefilename ~= filename) | (rest ~= title) Then
- Call WriteLn('tmp','@{" ' || filename || ' " link "' || file || '"}@{tab}' || title)
- state = 'end'
- End
- Call WriteLn('tmp',line)
- End
- When state = 'end' Then Do
- Call WriteLn('tmp',line)
- End
- End
- End
- Call Close('toc')
- End
- Call Close('tmp')
- End
- If state = 'end' Then
- Address Command 'Copy ' || tmpfile || ' TO ' || tocfile ' QUIET'
-
- Address Command 'Delete ' || tmpfile || ' QUIET'
- End
-
- Exit
-
-